package com.sophialex.health.record.common.audio;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;

import com.sophialex.health.record.common.Messages;

public class AudioTest {

	protected Shell shell;

	/**
	 * Launch the application.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			AudioTest window = new AudioTest();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setLayout(new FormLayout());
		shell.setSize(450, 300);
		shell.setText("SWT Application"); //$NON-NLS-1$
		{
			Button button = new Button(shell, SWT.NONE);
			button.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					FileDialog dlg = new FileDialog(shell, SWT.MULTI);
					dlg.open();
					String path = dlg.getFilterPath();
					// String[] names = dlg.getFileNames();
					String[] names = new String[] { "D.wav",Messages.AudioTest_2, Messages.AudioTest_3, "0.wav", //$NON-NLS-1$ //$NON-NLS-4$
							"1.wav", Messages.AudioTest_6, Messages.AudioTest_7, Messages.AudioTest_8 }; //$NON-NLS-1$
					PlayAudio.play(path, names);
				}
			});
			{
				FormData formData = new FormData();
				formData.top = new FormAttachment(0, 57);
				formData.left = new FormAttachment(0, 106);
				button.setLayoutData(formData);
			}
			button.setText("New Button"); //$NON-NLS-1$
		}

	}
}
